package com.book.item.controller;

import com.book.item.service.BookService;
import com.book.item.service.CateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.buchong.pojo.Book;
import com.buchong.pojo.CateGory;

import java.util.List;

@RequestMapping("/book")
@RestController
public class BookController {
    @Autowired
    private BookService bookService;
    @Autowired
    private CateService cateService;
    private CateController cateController = new CateController();

    @RequestMapping("/list")
    public List<Book> findAll() {
        List<Book> all = bookService.findAll();
        return all;
    }
    @RequestMapping("/selOne/{name}")
    public List<Book> findOne(@PathVariable("name") String name) {
        Integer id = cateService.finOne(name).getId();
        List<Book> all = bookService.findByID(id);
        return all;
    }
    @RequestMapping("/sel/{id}")
    public List<CateGory> fingByFirst(@PathVariable("id") Integer id) {
        List<CateGory> cateGories = cateService.finByFirst(id);
        return cateGories;

    }
    @RequestMapping("/sell/{id}")
    public Book fingOne(@PathVariable("id") Integer id) {
      return bookService.findOne(id);
    }
    @RequestMapping("/selll/{id}")
    public List<Book> fingOne1(@PathVariable("id") Integer id) {
        return bookService.findByID(id);

    }
    @RequestMapping("/selbyname/{name}")
    public List<Book> fingOne(@PathVariable("name") String  name) {
        return bookService.selByName(name);
    }

}
